//
//  ServerThreadController.h
//  Networking
//
//	We are using a multi threaded architecture, this is the controller class
// 	for the networking thread on the server, also takes care of client connections
//
//  Created by Christoph Eßer on 11/24/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Connection.h"
#import "ServerMessaging.h"

//cross-importing header files leads to problems...
@class ConnectionListener;


@interface ServerThreadController : NSObject <NetworkMessageHandler> {
    NSMutableDictionary *connections;
    NSMutableDictionary *abortedConnections;
    ConnectionListener *listener;
    NSThread *mainThread;
    NSThread *serverThread;
    
    NSObject<ServerMessaging> *messageDelegate;
}

@property (assign) NSObject<ServerMessaging> *messageDelegate;

-(void) newIncomingConnection: (Connection*) conn;

-(void) sendMessageToAllClients: (NetworkMessage*) msg;
-(void) sendMessage: (NetworkMessage*) msg toClient: (NSString*) client;

-(NSThread*) startServerThreadOnPort: (NSInteger) port;
-(void) stopServerThread;

@end
